import React, { Component } from 'react';
import { 
  Form,
  Input,
  Button
} from 'antd';

const ButtonGroup = Button.Group;
const FormItem = Form.Item;

class SettingForm extends Component {
  render(){
    const {
      form : {
        getFieldDecorator,
        validateFieldsAndScroll,
        getFieldError
      },
      allmoney,
      oneStockMoney,
      onOk,
      onCancel
    } = this.props;
    return (
      <div>
        <FormItem label="总金额">
          {
            getFieldDecorator("freemoney", {
              initialValue : allmoney,
              rules : [
                {
                  required : true,
                  message : '总金额不能为空'
                },{
                  pattern : /^[0-9]*$/gi,
                  message : '请检查金额是否填写正确'
                }
              ]
            })(<Input placeholder="请填写总金额"></Input>)
          }
        </FormItem>
        <FormItem label="单股最大金额">
          {
            getFieldDecorator("oneStockMoney", {
              initialValue : oneStockMoney,
              rules : [
                {
                  required : true,
                  message : '金额不能为空'
                },{
                  pattern : /^[0-9]*$/gi,
                  message : '请检查金额是否填写正确'
                }
              ]
            })(<Input placeholder="请填写单股最大金额"></Input>)
          }
        </FormItem>
        <ButtonGroup>
          <Button type="danger" onClick={onCancel}>取消</Button>
          <Button 
            type="primary"
            disabled={
              !!getFieldError("allmoney")
              }
            onClick={()=>{
              validateFieldsAndScroll((err, values)=>{
                if(!err){
                  onOk(values)
                }
              })
            }}
          >确定</Button>
        </ButtonGroup>
      </div>
    )
  }
}

export default Form.create()(SettingForm)